<?php 

namespace Home\Controller;
use Think\Controller;

class RegController extends Controller
{
	
	public function index(){
		if(isset($_SESSION['uid'])){
			$url=U('home/UserCenter/index');
			header('Location:'.$url);
			exit;
		}
		$question=D('vercode')->getOne();
		//var_dump($_SESSION['answer']);exit;
		$this->assign('question',$question);
		$this->assign('title','注册');
		$this->display();
	}

	public function checkdata(){
		$data = I('post.');
		$res = D('vercode')->checkCode($data['vercode']);
		if(!$res){
			$this->ajaxReturn(['error'=>1,'info'=>'人类验证不通过']);
		}
		
		$user = D('User');

		if(!$user->create($data,1)){
			$this->ajaxReturn(['error'=>1,'info'=>$user->getError()]);
		}else{
			$data['create_time'] = time();
			$data['password'] = md5($data['password']);

			if(M('user')->add($data)){
				$this->ajaxReturn(['error'=>0,'info'=>'注册成功']);
			}else{
				$this->ajaxReturn(['error'=>1,'info'=>'注册失败']);
			}
		}
		/*$resE = D('vercode')->checkEmail($data['email']);
		$resU = D('vercode')->checkUser($data['username']);
		$resP = D('vercode')->checkUser($data['pass']);
		if($resE == 2){
			exit(json_encode(['error'=>2,"info2"=>"邮箱格式不符合"]));
		}elseif($resE == 3){
			exit(json_encode(['error'=>3,"info3"=>"邮箱已存在"]));
		}
		if($reU == 5){
			exit(json_encode(['error'=>5,"info5"=>"账号格式不符合"]));
		}elseif($reU == 6){
			exit(json_encode(['error'=>6,"info6"=>"账户已存在"]));
		}
		if($resP == 7){
			exit(json_encode(['error'=>7,"info7"=>"账户已存在"]));
		}*/
		
	}

}


 ?>